import {
	ref,
	watch,
	computed,
	getCurrentInstance
} from "vue";
import {
	onLoad,onShow
} from "@dcloudio/uni-app";
import {
	getMyCarSource,carSell,carCancelSell,
	carDelete,carReSubmit,carUpdate,
	getMyCarSourceCount
} from "@/api/user/carSource";
import {
	savePhotos,
	navTo,
	showModel
} from '@/core/app';
export const useCarHook = (type) => {
	 //0待审核 1通过 2拒绝 -1关闭
	 const tabs = ref([])
	  //1求购 2收购 3批发 4车源  0所有
	 const initCarData = (data)=>{
		 switch (type){
			 case 1:
			  tabs.value = [{
			  		label: '求购中'+'('+data.countStatus1+')' ,
			  		value: '1'
			  	},
			  	{
			  		label: '待审核'+'('+data.countStatus0 +')',
			  		value: '0'
			  	},
			  	{
			  		label: '审核失败'+'('+data.countStatus2+')',
			  		value: '2'
			  	},
			  	{
			  		label: '已关闭'+'('+data.countStatus+')',
			  		value: '-1'
			  	}
			  ] 
			 break;
			 case 2:
			  tabs.value = [{
			  		label: '收购中'+'('+data.countStatus1+')' ,
			  		value: '1'
			  	},
			  	{
			  		label: '待审核'+'('+data.countStatus0+')' ,
			  		value: '0'
			  	},
			  	{
			  		label: '审核失败'+'('+data.countStatus2+')' ,
			  		value: '2'
			  	},
			  	{
			  		label: '已关闭'+'('+data.countStatus+')' ,
			  		value: '-1'
			  	}
			  ] 
			 break;
			 case 3:
			  tabs.value = [{
						label: '批发中'+'('+data.countStatus1+')' ,
						value: '1'
					},
					{
						label: '待审核'+'('+data.countStatus0+')' ,
						value: '0'
					},
					{
						label: '审核失败'+'('+data.countStatus2+')' ,
						value: '2'
					},
					{
						label: '已关闭'+'('+data.countStatus+')' ,
						value: '-1'
					}
				] 
			 break;
			 case 4:
			  tabs.value = [{
			  		label: '在库销售'+'('+data.countStatus1+')' ,
			  		value: '1'
			  	},
			  	{
			  		label: '待审核'+'('+data.countStatus0+')' ,
			  		value: '0'
			  	},
			  	{
			  		label: '审核驳回'+'('+data.countStatus2+')' ,
			  		value: '2'
			  	},
			  	{
			  		label: '已下架'+'('+data.countStatus+')' ,
			  		value: '-1'
			  	}
			  ] 
			 break;
			 case 5:
			 tabs.value = [{
			 		label: '询价中'+'('+data.countStatus1+')' ,
			 		value: '1'
			 	},
			 	{
			 		label: '已关闭'+'('+data.countStatus0 +')',
			 		value: '0'
			 	},
			 ]
		 }
			
	 }
	 const statusNum = ref(null)
	const getMyCarSourceCountApi = async(type)=>{
		let res = await getMyCarSourceCount({type})
		initCarData(res.data)
	}
	
		//更改状态
	const handleCheckState = async(item,status,statusText,callback)=>{
		showModel({
			content: '请确认是否'+statusText+'?',
			confirm: async () => {
				switch (status){
					case 0:
						await carDelete({id:item.id})
						break;
					case 1:
						await carCancelSell({id:item.id})
						break;
					case 2:
						await carReSubmit({id:item.id})
						break;
					case -1:
						await carSell({id:item.id})
						break;
				}
				callback()
			}
		})
	}
	return {
		tabs,
		statusNum,
		getMyCarSourceCountApi,
		handleCheckState
	}
}
